<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>公告页面</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" th:href="@{|/bootstrap-4.6.2/css/bootstrap.min.css|}">
    <script th:src="@{../jquery/jquery-3.6.0.min.js}"></script>
    <script th:src="@{../jquery/jquery.cookie.js}"></script>
    <script th:src="@{../bootstrap-4.6.2/js/bootstrap.bundle.min.js}"></script>
    <link th:href="@{|../css/program.css|}" rel="stylesheet" type="text/css" media="all" />
    <script th:src="@{|/js/getContextPath.js|}"></script>


</head>
<body>
<div class="container">
    <div class="box">
        <div class="title w">
            <h2>班费筹集事项公告</h2>
        </div>
    </div>
    <div class="btnList">
        <ul>
            <li><button  onclick="getProgramList()"  class="btn btn-primary">班费筹集项目列表</button></li>
            <li><button  onclick="getPayEvent()" class="btn btn-primary">查看需缴费项目</button></li>
            <li><button  onclick="getStuPay()" class="btn btn-primary">查看个人捐赠记录</button></li>
            <li> <button onclick="getIncomeList()"  class="btn btn-primary">查看班费收入清单</button></li>
            <li> <button  onclick="getOutEventList()" class="btn btn-primary">查看班费支出清单</button></li>
            <li> <button  class="btn  btn-primary"  data-toggle="modal" data-target="#exampleModal">修改个人信息</button></li>
            <li><a  class="btn btn-primary" href="/logout">退出登陆</a></li>
        </ul>
    </div>
    <div class="events w">
        <table id="tableEvent" class="table table-hover">
            <thead>
            <tr>
                <th>费用筹集内容</th>
                <th>费用预算筹集</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>具体操作</th>
            </tr>
            </thead>
            <tbody id="eventList">

            </tbody>
        </table>
    </div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">修改密码</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="password3">新密码:</label>
                        <input type="password" class="form-control"  placeholder="" id="password3">
                    </div>
                    <div class="form-group">
                        <label for="password4">确认密码:</label>
                        <input type="password" class="form-control" id="password4" placeholder="">
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button"  onclick="updatePassword()" class="btn btn-primary">修改</button>
            </div>
        </div>
    </div>
</div>
<script>
    getProgramList();
    function getProgramList() {
        $.ajax({
            url: "/student/selectEventIsDoing",
            type: "POST",
            dataType: "json",
            success: function (json) {
                if (json.code == 200) {
                    $("#tableEvent").empty();
                    for (let i = 0; i < json.data.length; i++) {
                        const event = json.data[i];
                        $("#tableEvent").append("<tr><td>" + event.eName +
                            "</td><td>" + event.ePay +
                            "</td><td>" + event.sTime +
                            "</td><td>" + event.eTime +
                            "</td><td>" + "<button class='btn btn-primary' onclick='toSupport(" + event.eid + ")'>去投票</button>" +
                            "</td></tr>");
                    }
                } else {
                    alert(json.msg);
                }
            }
        });
    }
    function getPayEvent() {
        $.ajax({
            url: "/student/getPayEvents",
            type: "POST",
            dataType: "json",
            success: function (json) {
                if (json.code == 200) {
                    $("#tableEvent").empty();
                    for (let i = 0; i < json.data.length; i++) {
                        const event = json.data[i];
                        $("#tableEvent").append("<tr><td>" + event.eName +
                            "</td><td>" + event.ePay +
                            "</td><td>" + event.sTime +
                            "</td><td>" + event.eTime +
                            "</td><td>" + "<button class='btn btn-primary' onclick='toPay(" + event.eid + ")'>去捐助</button>" +
                            "</td></tr>");
                    }
                } else {
                    alert(json.msg);
                }
            }
        });
    }
    function getStuPay() {
        let sid = $.cookie("sid");
        $.ajax({
            url: "/student/getStuOneList",
            type: "POST",
            data: {sid: sid},
            dataType: "json",
            success: function (json) {
                if (json.code == 200) {
                    $("#tableEvent").empty();
                    $("#tableEvent").append(" <tr> <td>" +
                        "捐赠人</td> <td>" +
                        "事件名称</td> <td>" +
                        "捐赠金额</td> <td>" +
                        "捐赠时间</td> </tr>");
                    for (let i = 0; i < json.data.length; i++) {
                        const event = json.data[i];
                        $("#tableEvent").append(
                            "<tr> <td>" + event.s_name +
                            "</td> <td>" + event.e_name +
                            "</td> <td>" + event.pay +
                            "</td> <td>" + event.pdate +
                            "</td> </tr>");
                    }
                } else {
                    alert(json.msg);
                }
            }
        });
    }
    function getIncomeList() {
        $.ajax({
            url: "/student/getIncomeList",
            type: "POST",
            dataType: "json",
            success: function (json) {
                if (json.code == 200) {
                    $("#tableEvent").empty();
                    $("#tableEvent").append(" <tr> <td>" +
                        "收入事由</td> <td>" +
                        "收入金额</td> <td>" +
                        "收入时间</td></tr>");
                    for (let i = 0; i < json.data.length; i++) {
                        const event = json.data[i];
                        $("#tableEvent").append(
                            "<tr> <td>" + event.in_name +
                            "</td> <td>" + event.in_money+
                            "</td> <td>" + event.in_date +
                            "</td> </tr>");
                    }
                } else {
                    alert(json.msg);
                }
            }
        });
    }
    function getOutEventList() {
        $.ajax({
            url: "/student/getOutEventList",
            type: "POST",
            dataType: "json",
            success: function (json) {
                if (json.code == 200) {
                    $("#tableEvent").empty();
                    $("#tableEvent").append(" <tr> <td>" +
                        "支出事由</td> <td>" +
                        "支出金额</td> <td>" +
                        "支出时间</td></tr>");
                    for (let i = 0; i < json.data.length; i++) {
                        const event = json.data[i];
                        $("#tableEvent").append(
                            "<tr> <td>" + event.pay_name +
                            "</td> <td>" + event.pay_money+
                            "</td> <td> " + event.pay_date +
                            "</td> </tr>");
                    }
                } else {
                    alert(json.msg);
                }
            }
        });
    }
    function updatePassword(){
        let sid= $.cookie("sid");
        let password3= $("#password3").val();
        let password4= $("#password4").val();
        if (password3==password4){
            $.ajax({
                url: "/student/updatePwd",
                type: "POST",
                data:{
                    sid:sid,
                    newpwd:password3,
                },
                dataType: "json",
                success: function (json) {
                    if (json.code==200){
                        alert(json.msg);
                        location.href="/loginPage";
                    }
                }
            });
        }else {
            alert("两次密码不一致!")
        }

    }
    function toSupport(eid) {
        $.cookie("eid", eid);
        location.href = "/event/echarts";
    }

    function toPay(eid) {
        $.cookie("eid", eid);
        location.href = "/event/toPayPage";
    }
    


</script>
</body>
</html>
